home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 634 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.3 KB  |  76 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: STL pop_back()
  5. Date: 05 Mar 1996 09:46:27 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Mar5125741@slsvgqt.lts.sel.alcatel.de>
  9. References: <4h4hmr$41o@news.rwth-aachen.de> <4h78mr$alj@engnews1.Eng.Sun.COM> <313BD2CA.7DBD@tiac.net>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 05 Mar 1996 11:57:41 GMT
  12. In-Reply-To: Hayden Schultz's message of 05 Mar 96 07:58:26 GMT
  13. Apparently-To: std-c++@ncar.ucar.edu
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMTx+AUy4NqrwXLNJAQGAWAH+KHICces0lounk47zMgOMhO+Ujm/2Eoai
  16.     t5iDCXv8q2cqq0+5Dy/oviUGzvMySFfvD9+W/E8SsLQIipxjnN4D3w==
  17.     =J8Mz
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. In article <313BD2CA.7DBD@tiac.net> Hayden Schultz <haydens@tiac.net>
  21. writes:
  22.  
  23. |> According to _STL Tutorial and Reference Guide_ by Musser and Saini
  24. |> (a very good book, btw), the following functions are defined:
  25.  
  26. |> template <class T> void vector<t>::pop_back();
  27. |> template <class T> void deque<t>::pop_back();
  28. |> template <class T> void deque<t>::pop_front();
  29. |> template <class T> void list<t>::pop_back();
  30. |> template <class T> void list<t>::pop_front();
  31.  
  32. |> Other classes may have pop functions, I dunno.
  33.  
  34. |> Why don't the pop functions return a copy of the object before they
  35. |> blow it away? Another possibility, I suppose, would be an auto_ptr<T>
  36. |> so that the object is deleted if it's not used. An auto_ptr<T> is
  37. |> about as efficient as deleting it in the pop function, it just changes
  38. |> the time it's deleted (which isn't guaranteed anywhere I've read
  39. |> anyway).
  40.  
  41. I suspect that no copy is returned because of performance reasons: to
  42. return one would require making the copy in every case (whether it was
  43. used or not), then destructing it.
  44.  
  45. I don't understand the remark concerning auto_ptr.  In order to return
  46. an auto_ptr to the object, it would be necessary to allocate a new
  47. copy of the object on the stack, then delete it.
  48.  
  49. I suppose some sort of intelligent reference could be returned, which
  50. would destruct the object whenever it was destructed.  This might
  51. still cause problems freeing the memory; I suppose that they would be
  52. solvable.
  53.  
  54. But is it worth it?
  55.  
  56. |> Why call the methods push and pop if it doesn't act like a stack?
  57.  
  58. That is the real question.  A list is not a stack.  A deque is not a
  59. stack.  A vector is not a stack.  The functions pop_front and pop_back
  60. have nothing to do with the operation pop on a stack.  This is why it
  61. is not worth the bother of having them return a value.  This is also
  62. why it probably would have been better if they'd have had another
  63. name. 
  64. -- 
  65. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  66. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  67. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  68.                 -- A la recherche d'une activitΘ dans une region francophone
  69. ---
  70. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  71.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  72.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  73.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  74.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  75. ]
  76.